#include <iostream>
#include <cstdlib>
#include <cstring>

using namespace std;
typedef unsigned long NUM;

bool is_palindromic (NUM num, NUM base)
{
	char str[25];
	itoa(num, str, base);
	int i = 0, size = strlen(str), mid = size--/2;
	while(i < mid && str[i] == str[size-i]) i++;
	return (i >= mid);
}

int main()
{
	NUM result = 0;

	for (NUM i = 1; i < 1000000; i++)
		if (is_palindromic(i, 10) && is_palindromic(i, 2))
			result += i;

	cout << result << endl;
	return 0;
}
